package org.gas.barapraja.route;

import org.gas.barapraja.proc.buffer.GasQueuePool;
import org.gas.barapraja.proc.buffer.MessageBufferQueue;

public class ServerTokenProvider implements ServerTokenDetails {
	
	private static volatile int token=100;
	
	private boolean enough=true;

	@Override
	public boolean tokenEnough() {
		MessageBufferQueue queue=(MessageBufferQueue)GasQueuePool.messageQueueInstance();
		if(token<queue.size())
			enough=false;
		return enough;
	}

	@Override
	public void updateSentToken(int token) {
		token-=token;
	}

	@Override
	public void updatePurchasedToken(int token) {
		token+=token;
	}

	@Override
	public int currentToken() {
		return token;
	}

}
